home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / WinCE / SDKWindowsCE / HandHeldPCPro30 / sdk.exe / Jupiter SDK / data1.cab / MFC / src / wcefont.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  8.0 KB  |  289 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. #ifndef __WCEFONT_H__
  12. #define __WCEFONT_H__
  13.  
  14. typedef void (CALLBACK *PFNADDREF) (void);
  15. typedef void (CALLBACK *PFNRELEASE) (void);
  16.  
  17.  
  18. DECLARE_INTERFACE(IInternalUnknown)
  19. {
  20.     STDMETHOD(InternalQueryInterface) (THIS_ REFIID riid, PVOID *ppv) PURE;
  21.     STDMETHOD_(ULONG, InternalAddRef) (THIS) PURE;
  22.     STDMETHOD_(ULONG, InternalRelease) (THIS) PURE;
  23. };
  24.  
  25. class CUnknown : public IInternalUnknown
  26. {
  27. public:
  28.  
  29.     CUnknown(IUnknown *pUnk);
  30.     CUnknown(void)
  31.     {
  32.         CUnknown(NULL);
  33.     }
  34.     //
  35.     // virtual destructors are a must!
  36.     //
  37.     virtual ~CUnknown(void);
  38.     //
  39.     // IInternalUnknown
  40.     //
  41.     STDMETHODIMP InternalQueryInterface(REFIID riid, PVOID *ppv);
  42.     STDMETHODIMP_(ULONG) InternalAddRef(void);
  43.     STDMETHODIMP_(ULONG) InternalRelease(void);
  44.     //
  45.     // Return the interface to the object that owns this object
  46.     //
  47.     IUnknown* GetOwner(void)
  48.     {
  49.         return m_pUnkOwner;
  50.     }
  51.     
  52.     //
  53.     // A simple wrapper that does a QueryInterface and AddRef
  54.     //
  55.     HRESULT GetInterface(IUnknown *pUnk, PVOID *ppv);
  56.     //
  57.     // For synchronization. This way, all objects are guaranteed consistent locking/unlocking
  58.     // mechanisms.
  59.     //
  60.     virtual void Lock(void)
  61.     {
  62.     }
  63.     
  64.     virtual void Unlock(void)
  65.     {
  66.     }
  67.  
  68.     static void SetFnAddRefRelease(PFNADDREF pfnAddRef, PFNRELEASE pfnRelease)
  69.     {
  70.         m_pfnAddRef = pfnAddRef;
  71.         m_pfnRelease = pfnRelease;
  72.     }
  73.  
  74.     void ClearRef(void)
  75.     {
  76.         Lock();
  77.         m_cRef = 0;
  78.         (*m_pfnRelease) ();
  79.         Unlock();
  80.     }
  81.  
  82.     //
  83.     // Data    
  84.     //
  85. protected:
  86.     LONG        m_cRef;                // ref count
  87.     IUnknown    *m_pUnkOwner;        // owning object - for aggregation
  88.     static PFNADDREF m_pfnAddRef;       // function to call when a ref count added
  89.     static PFNRELEASE m_pfnRelease;     // function to call when a ref count is released
  90.     static CRITICAL_SECTION  m_csUnkLock;  // common default critical section for all
  91. };
  92.  
  93.  
  94. //
  95. // fr - font record
  96. //
  97. struct FR
  98. {
  99.     CY       cySize;        // height, in points
  100.     LONG     cyLogical;
  101.     LONG     cyHimetric;
  102.     SHORT    sCharset;
  103.     SHORT    sWeight;
  104.     union {
  105.         struct{
  106.             BYTE fBold:1; // UNUSED: bold is determined from sWeight
  107.             BYTE fItalic:1;
  108.             BYTE fUnderline:1;
  109.             BYTE fStrikethrough:1;
  110.         };
  111.         BYTE bFlags;
  112.     };
  113.     OLECHAR  rgchFace[LF_FACESIZE];
  114. };
  115. //
  116. // Font types
  117. //
  118. #define FONT_fBold          0x01 // UNUSED
  119. #define FONT_fItalic        0x02
  120. #define FONT_fUnderline     0x04
  121. #define FONT_fStrikethrough 0x08
  122. #define FONT_fAll           0x0F
  123. //
  124. // Number of entries by which the font cache is grown
  125. //
  126. #define FONT_CACHE_GROWBY 8
  127. //
  128. // fcr - font cache record
  129. //
  130. struct FCR
  131. {
  132.     FR       frRequest;    // the font requested by the user
  133.     FR       frActual;    // the font window's actually supplied
  134.     ULONG    cRefs;
  135.     HFONT    hfont;
  136.     TEXTMETRICOLE tm;
  137. };
  138.  
  139.  
  140. //--------------------------------------------------------------------------------------------
  141. //
  142. // Classes
  143. //
  144. //--------------------------------------------------------------------------------------------
  145. class CCeFont :  public CUnknown,
  146.                  public IFont,
  147.                  public IFontDisp,
  148.                  public IPersistStream,
  149.                  public IPersistStreamInit,
  150.                  public IPersistPropertyBag
  151. {
  152. public:
  153.     CCeFont(void);
  154.     ~CCeFont(void);
  155.  
  156.     STDMETHODIMP QueryInterface(REFIID riid, PVOID *ppv)    
  157.     {                                                        
  158.         return GetOwner()->QueryInterface(riid, ppv);        
  159.     }                                                    
  160.                                                             
  161.     STDMETHODIMP_(ULONG) AddRef(void)                        
  162.     {                                                    
  163.         return GetOwner()->AddRef();                        
  164.     }                                                    
  165.                                                             
  166.     STDMETHODIMP_(ULONG) Release(void)                        
  167.     {                                                    
  168.         return GetOwner()->Release();                        
  169.     }                                                    
  170.     
  171.     STDMETHODIMP GetTypeInfoCount(UINT *pctInfo);        
  172.     
  173.     STDMETHODIMP GetTypeInfo(UINT itinfo, LCID lcid,        
  174.                             ITypeInfo **pptinfo);                                
  175.     
  176.     STDMETHODIMP GetIDsOfNames(REFIID riid,                
  177.                             OLECHAR **rgszNames,        
  178.                             UINT    cNames,                
  179.                             LCID    lcid,                
  180.                             DISPID    *rgdispids);            
  181.     
  182.     STDMETHODIMP Invoke(DISPID dispid,                        
  183.                         REFIID riid, LCID lcid, WORD wFlags,
  184.                         DISPPARAMS *pdispparams,            
  185.                         VARIANT *pVarResult, EXCEPINFO *pei,
  186.                         UINT *puArgErr);                        
  187.  
  188.     STDMETHODIMP get_Name(BSTR *pname);
  189.     STDMETHODIMP put_Name(BSTR name);
  190.  
  191.     STDMETHODIMP get_Size(CY *psize);
  192.     STDMETHODIMP put_Size(CY size);
  193.  
  194.     STDMETHODIMP get_Bold(BOOL *pbold);
  195.     STDMETHODIMP put_Bold(BOOL bold);
  196.     STDMETHODIMP get_Italic(BOOL *pitalic);
  197.     STDMETHODIMP put_Italic(BOOL italic);
  198.     STDMETHODIMP get_Underline(BOOL *punderline);
  199.     STDMETHODIMP put_Underline(BOOL underline);
  200.     STDMETHODIMP get_Strikethrough(BOOL *pstrikethrough);
  201.     STDMETHODIMP put_Strikethrough(BOOL strikethrough);
  202.     STDMETHODIMP get_Weight(short *pweight);
  203.     STDMETHODIMP put_Weight(short weight);
  204.     STDMETHODIMP get_Charset(short *pcharset);
  205.     STDMETHODIMP put_Charset(short charset);
  206.     STDMETHODIMP get_hFont(HFONT *phfont);
  207.     STDMETHODIMP Clone(IFont **lplpfont);
  208.     STDMETHODIMP IsEqual(IFont *lpFontOther);
  209.     STDMETHODIMP SetRatio(long cyLogical, long cyHimetric);
  210.     STDMETHODIMP QueryTextMetrics(LPTEXTMETRICOLE ptm);
  211.     STDMETHODIMP AddRefHfont(HFONT hfont);
  212.     STDMETHODIMP ReleaseHfont(HFONT hfont);
  213.     STDMETHODIMP SetHdc(HDC hdc);
  214.     //
  215.     // CUnknown overrides
  216.     //
  217.     STDMETHODIMP InternalQueryInterface(REFIID riid, PVOID *ppv);
  218.     //
  219.     // CCeFont
  220.     //
  221.     static HDC Hdc(void)
  222.     {
  223.         // Currently, we don't support the setting of a DC for every font, but when we
  224.         // do, this routine can return m_hdc
  225.         return m_hdc;
  226.     }
  227.  
  228.     HRESULT UpdateFont();
  229.     HRESULT DiscardFont(BOOL fNotify, DISPID dispidChanged);
  230.     HRESULT UpdateFr(HFONT hfont, TEXTMETRICOLE *ptm, OLECHAR rgchFace[LF_FACESIZE]);
  231.  
  232.     HRESULT NewFcr(int *pnFcr);
  233.     HRESULT ChkName(LPOLESTR szName);
  234.     HRESULT FindMatchingFont(int *pnFcr);
  235.     HRESULT CreateMatchingFont(HFONT *phfont);
  236.     HRESULT QueryFontInfo(HFONT hfont, TEXTMETRICOLE *ptm, OLECHAR rgchFace[LF_FACESIZE]);
  237.     //
  238.     // Statics
  239.     //
  240.     static HRESULT CreateFont(LPFONTDESC pfd, REFIID riid, PVOID *ppv);
  241.     static double RoundFloatDiv(double numer, double denom);
  242.     static HRESULT InitFontObject();
  243.     static HRESULT UninitFontObject();
  244.     static BOOL FontGetTextMetrics(HDC hdc, LPTEXTMETRICOLE ptm)
  245.     {
  246.         return GetTextMetricsW(hdc, ptm);
  247.     }
  248.     static int FontGetTextFace(HDC hdc, int cbBuffer, OLECHAR *szFace)
  249.     {
  250.         return GetTextFace(hdc, cbBuffer, szFace);
  251.     }
  252.  
  253.     // IPersistStream methods
  254.     STDMETHODIMP GetClassID(LPCLSID lpClassID);
  255.     STDMETHODIMP IsDirty();
  256.     STDMETHODIMP Load(LPSTREAM pStm);
  257.     STDMETHODIMP Save(LPSTREAM pStm,BOOL fClearDirty);
  258.     STDMETHODIMP GetSizeMax(ULARGE_INTEGER*);
  259.  
  260.     // IPersistPropertyBag methods
  261.     STDMETHODIMP InitNew();
  262.     STDMETHODIMP Load(LPPROPERTYBAG pPropBag, LPERRORLOG pErrorLog);
  263.     STDMETHODIMP Save(LPPROPERTYBAG pPropBag, BOOL fClearDirty, BOOL);
  264.  
  265. //
  266. // Data
  267. //
  268. protected:
  269.     FR    m_fr;            // Description of our font
  270.     HFONT m_hfont;      // The font handle
  271.     int   m_nFcr;        // Index to corresponding font cache record
  272.                         // (-1 if this object does not yet have a corresponding HFONT). 
  273.                         // NOTE: not a ptr because the font-cache-record may move
  274.                         // (if the font cache is realloc'd).
  275.     LONG  m_cRefs;
  276.     BYTE  m_fNameDirty:1;    // Used to minimize ammount of CharSet
  277.     BYTE  m_fCharSetDirty:1;    //  lookup we do.
  278.     static int  s_cFcr;        // Count of elements in the font cache
  279.     static FCR *s_rgfcr;    // The font cache - array of font cache records
  280.     static BOOL s_fInit;    // Has the font cache been initialized?
  281.     static HDC  m_hdc;
  282.  
  283.     BOOL m_bModified;
  284. };
  285.  
  286.  
  287. #endif //__WCEFONT_H__
  288.  
  289.